#include <stddef.h>
#include <malloc.h>
#include "stack.h"

void  initStack(SNode** s){
     *s = (SNode*)malloc(sizeof(SNode));
     (*s) -> next = NULL;
}

int pushStack(SNode* s,int data){
    SNode* temp = (SNode*)malloc(sizeof(SNode));
    if (temp == NULL){
        return 0;
    } else{
        temp -> next = s -> next;
        s -> next = temp;
        temp -> data = data;
        return 1;
    }

}

int popStack(SNode* s,int* data){
    if (isStackEmpty(s)){
        return 0;
    }else{
        SNode *p = s -> next;
        *data = p -> data;
        s -> next = p -> next;
        free(p);
        return 1;
    }
}

int isStackEmpty(SNode* s){
    return s -> next == NULL;
}

